﻿
<ul class="listPager">
    @if (Model.PageIndex > 0)
    {
        <li class="item" pageindex="@(Model.PageIndex-1)"><i class="fa fa-angle-left"></i> 上一页</li>
    }
    else
    {
        <li class="disabled"><i class="fa fa-angle-left"></i> 上一页</li>
    }


    @if (Model.TotalPage < 8)
    {
        for (int i = 0; i < Model.TotalPage; i++)
        {
            if (i == Model.PageIndex)
            {
                <li class="item current">@(i + 1)</li>
            }
            else
            {
                <li class="item" pageindex="@i">@(i + 1)</li>
            }
        }
    }
    else
    {
        if (Model.PageIndex < 4)
        {
            for (int i = 0; i < 5; i++)
            {
                if (i == Model.PageIndex)
                {
                    <li class="item current">@(i + 1)</li>
                }
                else
                {
                    <li class="item" pageindex="@i">@(i + 1)</li>
                }
            }
            <li>...</li>
            <li class="item" pageindex="@(Model.TotalPage - 2)">@(Model.TotalPage - 1)</li>
            <li class="item" pageindex="@(Model.TotalPage - 1)">@(Model.TotalPage)</li>
        }
        else if (Model.PageIndex >= Model.TotalPage - 4)
        {
            <li class="item" pageindex="0">1</li>
            <li class="item" pageindex="1">2</li>
            <li>...</li>
            for (int i = Model.TotalPage - 5; i < Model.TotalPage; i++)
            {
                if (i == Model.PageIndex)
                {
                    <li class="item current">@(i + 1)</li>
                }
                else
                {
                    <li class="item" pageindex="@i">@(i + 1)</li>
                }
            }
        }
        else
        {
            <li class="item" pageindex="0">1</li>
            <li>...</li>
            for (int i = Model.PageIndex - 2; i < Model.PageIndex + 3; i++)
            {
                if (i == Model.PageIndex)
                {
                    <li class="item current">@(i + 1)</li>
                }
                else
                {
                    <li class="item" pageindex="@i">@(i + 1)</li>
                }
            }
            <li>...</li>
            <li class="item" pageindex="@(Model.TotalPage - 1)">@(Model.TotalPage)</li>
        }

    }
    

    @if (Model.PageIndex + 1 < Model.TotalPage)
    {
        <li class="item" pageindex="@(Model.PageIndex+1)">下一页 <i class="fa fa-angle-right"></i></li>
    }
    else
    {

        <li class="disabled">下一页 <i class="fa fa-angle-right"></i></li>
    }



</ul>

